/**
 * 作者: wgx
 * 日期: 2024-11-15 16:44:35
 * 备注: 派对聊天记录表
 */
package com.motu.monstercity.server.game.userdata;

import com.motu.vertx.module.utility.model.BaseModel;
import com.motu.vertx.module.utility.model.Model;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;

public class FeastChatRecordModel extends BaseModel implements Model {
    public static final String LISTKEY = "feast_id";
    public static final int REDIS_EXPIRE_TIME = 0;// redis过期时间
    public static final int UPDATE_DB_TYPE = UPDATE_DB_TYPE_QUEUE;// 数据入库类型 队列入库
    public static final boolean ORDER_LIST = true;// 是否需要额外的有序列表

    protected long id; // ID
    protected long feastId; // 派对Id
    protected long userId; // 用户ID
    protected String userName = ""; // 用户名字
    protected int vip; // vip
    protected String content = ""; // 聊天内容
    protected long addTime; // 发言时间

    public void reset() {
    }

    protected String getKey() {
        return "FeastChatRecord." + id;
    }

    protected String getListKey() {
        return "FeastChatRecord." + feastId;
    }

    protected String getListItemKey() {
        return id + "";
    }

    public void doCreate() {
        setTableId();
        insert();
    }

    public void setTableId() {
        putId(incrTableId("feast_chat_record"));
    }

    public JsonObject insert() {
        return super.insert(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    public void delete() {
        super.delete(getKey(), id, UPDATE_DB_TYPE, 0, LISTKEY, getListKey(), getListItemKey(), ORDER_LIST);
    }

    /**
     * 根据入库类型更新
     */
    public JsonObject update() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    /**
     * 实时入队列
     */
    public JsonObject updateQueueNow() {
        return super.update(getKey(), id, REDIS_EXPIRE_TIME, UPDATE_DB_TYPE, 0, getAllObj(), LISTKEY, getListKey(), getListItemKey());
    }

    public JsonObject getAllObj(){
        JsonObject obj = new JsonObject();
        obj.put("id", id); // ID
        obj.put("feastId", feastId); // 派对Id
        obj.put("userId", userId); // 用户ID
        obj.put("userName", userName); // 用户名字
        obj.put("vip", vip); // vip
        obj.put("content", content); // 聊天内容
        obj.put("addTime", addTime); // 发言时间
        return obj;
    }

    public long getId() {
        return id;
    }

    public void putId(long id) {
        if (this.id != id) {
            this.id = id;
            updateRedisHashField(getKey(), "id", this.id);
        }
    }

    public void addId(long value) {
        this.id += value;
        updateRedisHashField(getKey(), "id", this.id);
    }

    public long getFeastId() {
        return feastId;
    }

    public void putFeastId(long feastId) {
        if (this.feastId != feastId) {
            this.feastId = feastId;
            updateRedisHashField(getKey(), "feastId", this.feastId);
        }
    }

    public void addFeastId(long value) {
        this.feastId += value;
        updateRedisHashField(getKey(), "feastId", this.feastId);
    }

    public long getUserId() {
        return userId;
    }

    public void putUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            updateRedisHashField(getKey(), "userId", this.userId);
        }
    }

    public void addUserId(long value) {
        this.userId += value;
        updateRedisHashField(getKey(), "userId", this.userId);
    }

    public String getUserName() {
        return userName;
    }

    public void putUserName(String userName) {
        if (!this.userName.equals(userName)) {
            this.userName = userName;
            updateRedisHashField(getKey(), "userName", this.userName);
        }
    }

    public int getVip() {
        return vip;
    }

    public void putVip(int vip) {
        if (this.vip != vip) {
            this.vip = vip;
            updateRedisHashField(getKey(), "vip", this.vip);
        }
    }

    public void addVip(int value) {
        this.vip += value;
        updateRedisHashField(getKey(), "vip", this.vip);
    }

    public String getContent() {
        return content;
    }

    public void putContent(String content) {
        if (!this.content.equals(content)) {
            this.content = content;
            updateRedisHashField(getKey(), "content", this.content);
        }
    }

    public long getAddTime() {
        return addTime;
    }

    public void putAddTime(long addTime) {
        if (this.addTime != addTime) {
            this.addTime = addTime;
            updateRedisHashField(getKey(), "addTime", this.addTime);
        }
    }

    public void addAddTime(long value) {
        this.addTime += value;
        updateRedisHashField(getKey(), "addTime", this.addTime);
    }

}